<script lang="ts">
	// 获取本地音视频流
	// import Button from '$lib/button.svelte';
	import Video from '$lib/video.svelte';
	async function createPeerConnection() {}
	let stream: MediaStream;
	async function getLocalStream() {
		// 获取媒体流
		stream = await navigator.mediaDevices.getUserMedia({
			audio: false,
			video: true
		});
		console.log(stream);
		console.log('🚀🚀🚀 / SupportedConstraints', navigator.mediaDevices.getSupportedConstraints());
	}
	import { io, Socket } from 'socket.io-client';
	import { onMount } from 'svelte';
	let socket: Socket;
	onMount(() => {
		socket = io();
		// 连接到信令服务 WebRTC 是需要在 https 协议下才能使用的 本地不需要
		// const socket = io("http://localhost:8080");
		socket.on('connect', () => {
			console.log(socket.connected); // true
		});
		socket.on('disconnect', () => {
			console.log(socket.connected); // false
		});
		socket.on('message', (data) => {
			console.log(data);
		});
	});
	let inputvalue: string;
	function oncmit() {
		// socket.emit('message', inputvalue);
		socket.on('message', (inputvalue) => {
			console.log(inputvalue);
		});
	}
</script>

<Video {stream} />

<button id="button-showvideo" on:click={getLocalStream}>打开摄像头</button>

<p>{crypto.randomUUID()}</p>

<!-- <Button /> -->

{#if inputvalue}
	{inputvalue}
{/if}
<input type="text" bind:value={inputvalue} />
<button bg-green on:click={oncmit}>发送</button>
